1 /*
2  * Copyright (c) 2011-2012 - Mauro Carvalho Chehab
3  * Copyright (c) 2012 - Andre Roth <neolynx@gmail.com>
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU Lesser General Public License as published by
7  * the Free Software Foundation version 2.1 of the License.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17  * Or, point your browser to http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
18  *
19  */
20 
21 /**
22  * @file pat.h
23  * @ingroup dvb_table
24  * @brief Provides the descriptors for PAT MPEG-TS table
25  * @copyright GNU Lesser General Public License version 2.1 (LGPLv2.1)
26  * @author Mauro Carvalho Chehab
27  * @author Andre Roth
28  *
29  * @par Relevant specs
30  * The table described herein is defined at:
31  * - ISO/IEC 13818-1
32  *
33  * @see http://www.etherguidesystems.com/help/sdos/mpeg/syntax/tablesections/pat.aspx
34  *
35  * @par Bug Report
36  * Please submit bug reports and patches to linux-media@vger.kernel.org
37  */
38 
39 module libdvbv5_d.pat;
40 
41 import core.sys.posix.unistd;
42 
43 import libdvbv5_d.dvb_fe: dvb_v5_fe_parms;
44 import libdvbv5_d.header: dvb_table_header;
45 
46 extern (C):
47 
48 /* ssize_t */
49 
50 /**
51  * @def DVB_TABLE_PAT
52  *	@brief PAT table ID
53  *	@ingroup dvb_table
54  * @def DVB_TABLE_PAT_PID
55  *	@brief PAT Program ID
56  *	@ingroup dvb_table
57  */
58 enum DVB_TABLE_PAT = 0x00;
59 enum DVB_TABLE_PAT_PID = 0x0000;
60 
61 /**
62  * @struct dvb_table_pat_program
63  * @brief MPEG-TS PAT program table
64  * @ingroup dvb_table
65  *
66  * @param service_id	service id
67  * @param pid		pid
68  * @param next		pointer to struct dvb_table_pat_program
69  *
70  * This structure is used to store the original PAT program table,
71  * converting the integer fields to the CPU endianness.
72  *
73  * The undocumented parameters are used only internally by the API and/or
74  * are fields that are reserved. They shouldn't be used, as they may change
75  * on future API releases.
76  *
77  * Everything after dvb_table_pat_program::next (including it) won't be bit-mapped
78  * to the data parsed from the MPEG TS. So, metadata are added there.
79  */
80 struct dvb_table_pat_program
81 {
82     align (1):
83 
84     ushort service_id;
85 
86     union
87     {
88         align (1):
89 
90         ushort bitfield;
91 
92         struct
93         {
94             import std.bitmanip : bitfields;
95             align (1):
96 
97             mixin(bitfields!(
98                 ushort, "pid", 13,
99                 ubyte, "reserved", 3));
100         }
101     }
102 
103     dvb_table_pat_program* next;
104 }
105 
106 /**
107  * @struct dvb_table_pat
108  * @brief MPEG-TS PAT table
109  * @ingroup dvb_table
110  *
111  * @param header	struct dvb_table_header content
112  * @param programs	number of programs
113  * @param program	pointer to struct dvb_table_pat_program
114 
115  * This structure is used to store the original PAT table,
116  * converting the integer fields to the CPU endianness.
117  *
118  * The undocumented parameters are used only internally by the API and/or
119  * are fields that are reserved. They shouldn't be used, as they may change
120  * on future API releases.
121  *
122  * Everything after dvb_table_pat_program::program (including it) won't be bit-mapped
123  * to the data parsed from the MPEG TS. So, metadata are added there.
124  */
125 struct dvb_table_pat
126 {
127     align (1):
128 
129     dvb_table_header header;
130     ushort programs;
131     dvb_table_pat_program* program;
132 }
133 
134 /**
135  * @brief Macro used to find programs on a PAT table
136  * @ingroup dvb_table
137  *
138  * @param _pgm		program to seek
139  * @param _pat		pointer to struct dvb_table_pat_program
140  */
141 
142 // struct dvb_v5_fe_parms;
143 
144 /**
145  * @brief Initializes and parses PAT table
146  * @ingroup dvb_table
147  *
148  * @param parms	struct dvb_v5_fe_parms pointer to the opened device
149  * @param buf buffer containing the PAT raw data
150  * @param buflen length of the buffer
151  * @param table pointer to struct dvb_table_pat to be allocated and filled
152  *
153  * This function allocates a PAT table and fills the fields inside
154  * the struct. It also makes sure that all fields will follow the CPU
155  * endianness. Due to that, the content of the buffer may change.
156  *
157  * @return On success, it returns the size of the allocated struct.
158  *	   A negative value indicates an error.
159  */
160 ssize_t dvb_table_pat_init (
161     dvb_v5_fe_parms* parms,
162     const(ubyte)* buf,
163     ssize_t buflen,
164     dvb_table_pat** table);
165 
166 /**
167  * @brief Frees all data allocated by the PAT table parser
168  * @ingroup dvb_table
169  *
170  * @param table pointer to struct dvb_table_pat to be freed
171  */
172 void dvb_table_pat_free (dvb_table_pat* table);
173 
174 /**
175  * @brief Prints the content of the PAT table
176  * @ingroup dvb_table
177  *
178  * @param parms	struct dvb_v5_fe_parms pointer to the opened device
179  * @param table pointer to struct dvb_table_pat
180  */
181 void dvb_table_pat_print (dvb_v5_fe_parms* parms, dvb_table_pat* table);